import axiosInstance from './axiosInstance';

class VideoService {
  /**
   * 获取视频列表
   * @param params 查询参数
   * @returns 分页视频数据
   */
  async getVideos(params) {
    try {
      const response = await axiosInstance.get('/videos', { params });
      return response.data;
    } catch (error) {
      console.error('获取视频列表失败:', error);
      throw error;
    }
  }

  /**
   * 获取视频详情
   * @param id 视频ID
   * @returns 视频详情
   */
  async getVideoDetail(id) {
    try {
      const response = await axiosInstance.get(`/videos/${id}`);
      return response.data;
    } catch (error) {
      console.error('获取视频详情失败:', error);
      throw error;
    }
  }

  /**
   * 更新视频状态
   * @param id 视频ID
   * @param status 新状态
   * @returns 更新结果
   */
  async updateVideoStatus(id, status) {
    try {
      const response = await axiosInstance.put(`/videos/${id}/status`, { status });
      return response;
    } catch (error) {
      console.error('更新视频状态失败:', error);
      throw error;
    }
  }

  /**
   * 删除视频
   * @param id 视频ID
   * @returns 删除结果
   */
  async deleteVideo(id) {
    try {
      const response = await axiosInstance.delete(`/videos/${id}`);
      return response;
    } catch (error) {
      console.error('删除视频失败:', error);
      throw error;
    }
  }

  /**
   * 批量删除视频
   * @param ids 视频ID数组
   * @returns 删除结果
   */
  async batchDeleteVideos(ids) {
    try {
      const response = await axiosInstance.post('/videos/batch-delete', { ids });
      return response;
    } catch (error) {
      console.error('批量删除视频失败:', error);
      throw error;
    }
  }
}

export default new VideoService();